package com.penghaisoft.microwms.material.web.insidewarehouse.controller;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.penghaisoft.microwms.common.Constant;
import com.penghaisoft.microwms.common.controller.BaseController;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.dto.TransResult;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.service.IWmsCommonService;
import com.penghaisoft.microwms.common.wms.model.RawCountingTask;
import com.penghaisoft.microwms.material.web.insidewarehouse.service.IMaterialInsideService;

/** 
* @ClassName: InsideRawCountingTaskController 
* @Description: 原材料盘点任务
* @author jzh
* @date 2018年5月24日 上午10:41:28  
*/
@RestController
@RequestMapping(value = "insidewarehouse/rawcountingtask")
@Slf4j
public class InsideRawCountingTaskController extends BaseController  {
	
	@Autowired
	private IMaterialInsideService iMaterialInsideService;
	
	@Autowired
	private IWmsCommonService wmsCommonService;
	
	@PostMapping("list")
	public TransResult list(@RequestParam(name = "page", defaultValue = "1") int page,
                            @RequestParam(name = "rows", defaultValue = "10") int rows, RawCountingTask rawCountingTask) {
		
		Pager<RawCountingTask> result = iMaterialInsideService.findCountingTask(page, rows, rawCountingTask);
		return success(result);
	}
	
	@PostMapping("c")
	public TransResult create(RawCountingTask rawCountingTask) {
		String countingCode = wmsCommonService.getProShortSeq5(Constant.SEQ_PREFIX_SHORT_PD, Constant.SEQ_PREFIX_SHORT_REDIS_PRO_PD, 1).get(0);
		rawCountingTask.setCountingCode(countingCode);
		rawCountingTask.setCreateBy(getLoginName());
		rawCountingTask.preInsert();
		rawCountingTask.setActiveFlag("1");
		rawCountingTask.setCountingType("1");
		rawCountingTask.setStauts("0");
		Resp resp =  iMaterialInsideService.createCountingTask(rawCountingTask);
		return fromResp(resp);
	}
	
	/** 
	* @Title: createAllCheck 
	* @Description: 全盘单创建
	* @param @param rawCountingTask
	* @param @return  参数说明 
	* @return TransResult    返回类型
	* @author jzh 
	* @throws 
	*/
	@PostMapping("createAllCheck")
	public TransResult createAllCheck(RawCountingTask rawCountingTask) {
		String countingCode = wmsCommonService.getProShortSeq5("QP", Constant.SEQ_PREFIX_SHORT_REDIS_PRO_PD, 1).get(0);
		rawCountingTask.setCountingCode(countingCode);
		rawCountingTask.setCreateBy(getLoginName());
		rawCountingTask.preInsert();
		rawCountingTask.setActiveFlag("1");
		rawCountingTask.setCountingType("2");//2全盘
		rawCountingTask.setStauts("0");
		Resp resp =  iMaterialInsideService.createCountingTask(rawCountingTask);
		return fromResp(resp);
	}
	
	@PostMapping("d")
	public TransResult delete(RawCountingTask rawCountingTask) {
		rawCountingTask.preUpdate();
		Resp resp =  iMaterialInsideService.deleteCountingTask(rawCountingTask);
		return fromResp(resp);
	}

}
